1
|
|
|
/** |
2
|
|
|
* Asynchronously save all settings in the current settings page to the database. |
3
|
|
|
* Shows an error notification if errors occur. Shows a success notification |
4
|
|
|
* otherwise. |
5
|
|
|
* |
6
|
|
|
* @param {Function} done |
7
|
|
|
*/ |
8
|
|
|
Amarkal.settings.save = function( done ) |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
Amarkal.settings._postData('save',function(res){ |
|
|
|
|
11
|
|
|
|
12
|
|
|
Amarkal.settings._clearErrors(); |
|
|
|
|
13
|
|
|
|
14
|
|
|
if(!$.isEmptyObject(res.errors)) { |
15
|
|
|
for(var name in res.errors) { |
|
|
|
|
16
|
|
|
var $comp = $('[amarkal-component-name="'+name+'"]'); |
17
|
|
|
|
18
|
|
|
$comp.amarkalUIComponent('makeInvalid'); |
19
|
|
|
$comp.parent() |
20
|
|
|
.children('.amarkal-settings-error') |
21
|
|
|
.addClass('amarkal-visible') |
22
|
|
|
.html(res.errors[name]); |
23
|
|
|
} |
24
|
|
|
Amarkal.settings.notifier.error('Some errors have occured, see below for more information.'); |
25
|
|
|
} |
26
|
|
|
else { |
27
|
|
|
Amarkal.settings.notifier.success('Settings saved', 2000); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
$('#amarkal-settings-form').amarkalUIForm('setData', res.values, res.errors); |
31
|
|
|
|
32
|
|
|
done(); |
33
|
|
|
}); |
34
|
|
|
}; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Asynchronously reset all settings in the current settings page to their |
38
|
|
|
* default values and erase all data from the database. Shows a success |
39
|
|
|
* notification upon completion. |
40
|
|
|
* |
41
|
|
|
* @param {Function} done |
42
|
|
|
*/ |
43
|
|
|
Amarkal.settings.reset = function( done ) |
44
|
|
|
{ |
45
|
|
|
Amarkal.settings._postData('reset',function(res){ |
|
|
|
|
46
|
|
|
|
47
|
|
|
Amarkal.settings._clearErrors(); |
|
|
|
|
48
|
|
|
Amarkal.settings.notifier.success('Default settings applied', 2000); |
49
|
|
|
$('#amarkal-settings-form').amarkalUIForm('setData', res.values, res.errors); |
50
|
|
|
|
51
|
|
|
done(); |
52
|
|
|
}); |
53
|
|
|
}; |
54
|
|
|
|
55
|
|
|
Amarkal.settings._clearErrors = function() |
56
|
|
|
{ |
57
|
|
|
// Reset all components |
58
|
|
|
$('.amarkal-ui-component').amarkalUIComponent('reset'); |
59
|
|
|
$('.amarkal-settings-error').removeClass('amarkal-visible').html(''); |
60
|
|
|
}; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Update all components in the current settings page with the given values. |
64
|
|
|
* |
65
|
|
|
* @param {Object} values |
66
|
|
|
* @param {Array} errors |
67
|
|
|
*/ |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Send serialized form data to be processed in the backend by the function given |
71
|
|
|
* in the 'action' variable. |
72
|
|
|
* |
73
|
|
|
* @param {string} action |
74
|
|
|
* @param {Function} done |
75
|
|
|
*/ |
76
|
|
|
Amarkal.settings._postData = function( action, done ) |
|
|
|
|
77
|
|
|
{ |
78
|
|
|
var data = $('#amarkal-settings-form').amarkalUIForm('getData'); |
79
|
|
|
$('#amarkal-settings-form').find('input[name^="_amarkal"]').each(function(){ |
80
|
|
|
data[$(this).attr('name')] = $(this).val(); |
81
|
|
|
}); |
82
|
|
|
|
83
|
|
|
$.post(ajaxurl, { |
|
|
|
|
84
|
|
|
action: 'amarkal_settings_'+action, |
85
|
|
|
data: data |
86
|
|
|
}, done); |
87
|
|
|
}; |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.